package com.situ.blog.service.impl;

import com.situ.blog.dao.IBlogDao;
import com.situ.blog.dao.impl.BlogDaoImpl;
import com.situ.blog.pojo.Blog;
import com.situ.blog.service.IBlogService;
import com.situ.blog.util.JSONResult;
import com.situ.blog.util.LayUITableJSONResult;

import java.util.List;

public class BlogServiceImpl implements IBlogService {
    private IBlogDao blogDao = new BlogDaoImpl();

    @Override
    public LayUITableJSONResult selectByPage(Integer page, Integer limit) {
        int offset = (page - 1) * limit;
        List<Blog> list = blogDao.selectByPage(offset, limit);
        int totalCount = blogDao.selectTotalCount();

        return LayUITableJSONResult.ok(totalCount, list);
    }

    @Override
    public JSONResult add(Blog blog) {
        int count = blogDao.add(blog);
        return count == 1 ? JSONResult.ok("添加成功") : JSONResult.error("添加失败");
    }
}
